<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>web_socket.js</title>
    <script type="text/javascript">
        //是否强制使用flash websocket
        WEB_SOCKET_FORCE_FLASH = true;
    </script>
</head>
<body onload="init();">
<form onsubmit="onSubmit(); return false;">
    <input type="text" id="input">
    <input type="submit" value="Send">
    <button onclick="onCloseClick(); return false;">close</button>
</form>
<div id="log"></div>
<!-- Include these three JS files: -->
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript" src="web_socket.js"></script>
<script type="text/javascript">

    // Set URL of your WebSocketMain.swf here:
    WEB_SOCKET_SWF_LOCATION = "WebSocketMain.swf";
    // Set this to dump debug message from Flash to console.log:
    WEB_SOCKET_DEBUG = true;

    // Everything below is the same as using standard WebSocket.

    var ws;

    function init() {

        // Connect to Web Socket.
        // Change host/port here to your own Web Socket server.
        // ws = new WebSocket("ws://localhost:10081/");
        ws = new WebSocket("ws://10.97.208.98:8000/");

        // Set event handlers.
        ws.onopen = function () {
            output("onopen");
        };
        ws.onmessage = function (e) {
            // e.data contains received string.
            output("onmessage: " + e.data);
        };
        ws.onclose = function () {
            output("onclose");
        };
        ws.onerror = function () {
            output("onerror");
        };

    }

    function onSubmit() {
        var input = document.getElementById("input");
        // You can send message to the Web Socket using ws.send.
        ws.send(input.value);
        output("send: " + input.value);
        input.value = "";
        input.focus();
    }

    function onCloseClick() {
        ws.close();
    }

    function output(str) {
        var log = document.getElementById("log");
        var escaped = str.replace(/&/, "&amp;").replace(/</, "&lt;").replace(/>/, "&gt;").replace(/"/, "&quot;"); // "
        log.innerHTML = escaped + "<br>" + log.innerHTML;
    }

</script>
</body>
</html>